﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using TMS.DAL;
using TMS.Model;

namespace TMS.UI.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class RoomTypeController : ControllerBase
    {
        public RoomTypeController(RoomDal roomDal)
        {
            RoomDal = roomDal;
        }

        public RoomDal RoomDal { get; }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="Roomtype"></param>
        /// <returns></returns>
        /// 
        [HttpPost("Add")]
        public IActionResult Add(Roomtype Roomtype)
        {
            int res = RoomDal.checkname(Roomtype.Rname);
            if(res>0)
            {
                return Ok(new { data = -1 });
            }
            else
            {
                int r=RoomDal.Add(Roomtype);
                if(r>0)
                {
                    return Ok(new { data = 1 });
                }
                else
                {
                    return Ok(new { data = 2  });
                }
            }

        }
        /// <summary>
        /// 查询房型名称是否重复
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        /// 
        [HttpGet("checkname")]
        public IActionResult checkname(string name)
        {
            var res=RoomDal.checkname(name);
            return Ok(new { data = res });
        }
        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpGet("GetRoomtype")]
        public IActionResult GetRoomtype()
        {
           var res= RoomDal.GetRoomtype();
            return Ok(new { data = res });
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// 
        [HttpGet("Fantian")]
        public IActionResult Fantian(int id)
        {
           var res=RoomDal.Fantian(id);
            return Ok(new { data = res });
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="Roomtype"></param>
        /// <returns></returns>
        /// 
        [HttpPost("Update")]
        public IActionResult Update(Roomtype Roomtype)
        {
           var res=RoomDal.Update(Roomtype);
            return Ok(new { data = res });
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="states"></param>
        /// <returns></returns>
        /// 
        [HttpGet("upda")]
        public IActionResult upda(int id, int states)
        {
           var res=RoomDal.upda(id, states);
            return Ok(new { data = res });
        }
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// 
        [HttpGet("delete")]
        public IActionResult delete(int id)
        {
            var res=RoomDal.delete(id);
            return Ok(new { data = res });
        }
    }
}
